package com.gj.serializer;

import com.alibaba.fastjson.JSON;
import com.gj.model.TransactionMessage;
import org.apache.kafka.common.errors.SerializationException;
import org.apache.kafka.common.serialization.Serializer;

import java.util.Map;

/**
 * author:guijie
 * date:${date}
 * description:TODO
 */
public class ObjectSerializer implements Serializer<TransactionMessage> {

    @Override
    public byte[] serialize(String s, TransactionMessage message) {
        try {
            return message == null ? null : JSON.toJSONBytes(message);
        }catch (Exception e){
            throw new SerializationException("序列化错误");
        }
    }

}
